using System.IO;
using UnityEditor;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    public class GenAnimatorLevelEntity : GenAnimatorBase
    {
        public override ArtModeGenType genAnimatorType => ArtModeGenType.LevelEntity;
        
        protected override string entityGenConfigPath => $"Assets/EditorConfig/ArtToolConfig/EntityGen/Entity/{entityName}.asset";
        protected override string defaultGenConfigPath => "Assets/EditorConfig/ArtToolConfig/EntityGen/Common/Entity_LevelEntity.asset";
        public override void GenAnimatorController()
        {
            if (string.IsNullOrEmpty(this.entityName))
            {
                return;
            }

            //// create animator controller
            CreateController();
            //// add controller parameters
            AddParameters();
            //// Create Anim States
            CreateAnimStates();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }

        /// <summary>
        /// 获取动画资源路径
        /// </summary>
        /// <returns></returns>
        public override string GetAnimatorResPath()
        {
            var animatorResPath = Path.Combine(basePath, $"{entityName}_animator.controller");
            return animatorResPath;
        }

        protected virtual void CreateAnimStates()
        {
            CreateBaseLayerState();

            CreateCustomLayerState();
        }

        public void CreateBaseLayerState()
        {
            // 创建基础状态
            var stateDefault = CreateBaseIdleState(baseLayerMachine, true, new Vector3(xOffset, 0));
            AddResetToDefaultState(baseLayerMachine);
            // 创建长时间休闲状态
            _ = CreateLongIdleState(baseLayerMachine, new Vector3(0, 2 * yOffset), stateDefault);
            // 创建转向状态
            _ = CreateTurnState(baseLayerMachine, new Vector3(xOffset, yOffset), stateDefault);
            // 创建出生动画
            _ = CreateBornState(baseLayerMachine, new Vector3(0, -2 * yOffset), stateDefault);
            // 创建死亡状态(如果有的情况下)
            _ = CreateDieState(baseLayerMachine, new Vector3(xOffset, -yOffset));
            // 创建跳跃状态(如果有的情况下)
            _ = CreateJumpState(baseLayerMachine, new Vector3(xOffset * 2, -yOffset * 2), stateDefault);


            CreateCustomAction(baseLayerMachine, 0, xOffset * 3, baseLayerMachine.defaultState);


            AddStateBehaviour(baseLayerMachine);
        }

    }
}
